{extend name="public/base" /}

{block name="title"}{$systems.webname}{/block}

{block name="main"}
<div class="main">
    <div class="col-sm-12 col-md-8">
        <h1 class="article-title">{$article.title}</h1>
        <div class="status">{$article.click}阅读-{$article.comment}评论-作者：{$article.author}
            {volist name="tags" as id="vo"}
            <span class="label label-default">{$vo}</span>
            {/volist}
        </div>
        <div class="article-content">
            <blockquote>
                {$article.desc}
            </blockquote>
            {$article.content|raw}
        </div>
        <div class="article-comment">
            <div class="page-header"><b>相关评论</b></div>
            <div class="comment-content">
                <form action="#">
                    <div class="form-group">
                        <textarea class="form-control" id="comment" name="comment" rows="5" cols=""></textarea>
                    </div>
                    <div class="form-group pull-right">
                        <button class="btn btn-primary" type="submit" id="comBtn">评论（请认真评论）</button>
                    </div>
                </form>
            </div>
            <div class="clearfix"></div>
            {volist name="comments" as id="vo"}
            <div class="comment-list">
                <div class="comment-list-item">
                    <div class="info">小黑<small>{$vo.create_time}</small></div>
                    <div class="content">{$vo.content}</div>
                </div>
            </div>
            {/volist}
        </div>
    </div>
    <div class="col-sm-12 col-md-4">
        <div class="page-header h3">推荐文章</div>
        <div class="topic-list">
            {volist name="articleTop" as id="vo"}
            <div class="topic-list-item">
                <a href="#" class="title">{$vo.title}</a>
            </div>
            {/volist}
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    $(function () {

        $("#comBtn").on('click', function () {
            console.log(getCookie('id'));
            let memberId = getCookie("id");
            let content = $('#comment').val();
            if (!memberId){
                layer.msg("请先登录", {
                    icon: 5,
                    time: 2000
                });
            }else{
                $.ajax({
                    url: "{:url('index/article/comment')}",
                    type: "post",
                    data: {
                        article_id: "{$article.id}",
                        member_id: memberId,
                        content: content,
                    },
                    dataType: "json",
                    success: res => {
                        console.log(res);
                        if (res.code == 1) {
                            layer.msg(res.msg, {
                                icon: 6,
                                time: 2000
                            }, function () {
                                location.href = res.url;
                            })
                        } else {
                            layer.open({
                                content: res.msg,
                                icon: 5
                            })
                        }
                    }
                });
            }


            return false;
        });
    })

    function getCookie(name) {
        var strcookie = document.cookie;//获取cookie字符串
        var arrcookie = strcookie.split("; ");//分割
//遍历匹配
        for (var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split("=");
            if (arr[0] == name) {
                return arr[1];
            }
        }
        return "";
    }
</script>
{/block}